//
//  TaskManagerNavBar.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2021/3/19.
//  Copyright © 2021 吕晶. All rights reserved.
//

#import "TaskManagerNavBar.h"

@interface TaskManagerNavBar ()

@property (nonatomic, strong) UIButton *backBtn;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIButton *btn1;
@property (nonatomic, strong) UIButton *btn4;
@property (nonatomic, strong) UIButton *btn2;
@property (nonatomic, strong) UIButton *btn3;

@end

@implementation TaskManagerNavBar

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = HexColor(0xffffff);
        
        self.backBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, StatusBarHeight+(NaviHeight - StatusBarHeight - 24) * 0.5, 24, 24)];
        [self.backBtn setImage:[UIImage imageNamed:@"nav_back"] forState:0];
        [self.backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.backBtn];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(self.backBtn.nim_right + 15, self.backBtn.nim_top + 2.5, 80, 19)];
        self.titleLab.textColor = HexColor(0x000000);
        self.titleLab.font = BoldFontOfSize(18);
        [self addSubview:self.titleLab];
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(ScreenW - 15 - 172 - 4 - 52, StatusBarHeight+(NaviHeight - StatusBarHeight - 40) * 0.5, 172 + 4 + 52, 40)];
        self.bgView.backgroundColor = HexColor(0xF2F2F5);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 8;
        [self addSubview:self.bgView];
        
        self.btn4 = [[UIButton alloc] initWithFrame:CGRectMake(4, 4, 52, 32)];
        [self.btn4 setTitle:@"计划" forState:0];
        self.btn4.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn4 setTitleColor:HexColor(0x9C9DB3) forState:0];
        self.btn4.layer.masksToBounds = YES;
        self.btn4.layer.cornerRadius = 6;
        [self.btn4 setBackgroundColor:HexColor(0xF2F2F5)];
        [self.btn4 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        self.btn4.tag = 11;
        [self.bgView addSubview:self.btn4];
        
        self.btn1 = [[UIButton alloc] initWithFrame:CGRectMake(self.btn4.nim_right + 4, 4, 52, 32)];
        [self.btn1 setTitle:@"未完成" forState:0];
        self.btn1.titleLabel.font = BoldFontOfSize(14);
        [self.btn1 setTitleColor:HexColor(0xffffff) forState:0];
        self.btn1.layer.masksToBounds = YES;
        self.btn1.layer.cornerRadius = 6;
        [self.btn1 setBackgroundColor:Color_ThemeColor];
        [self.btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        self.btn1.tag = 1;
        [self.bgView addSubview:self.btn1];
        
        self.btn2 = [[UIButton alloc] initWithFrame:CGRectMake(self.btn1.nim_right + 4, 4, 52, 32)];
        [self.btn2 setTitle:@"已完成" forState:0];
        self.btn2.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn2 setTitleColor:HexColor(0x9C9DB3) forState:0];
        self.btn2.layer.masksToBounds = YES;
        self.btn2.layer.cornerRadius = 6;
        [self.btn2 setBackgroundColor:HexColor(0xF2F2F5)];
        [self.btn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        self.btn2.tag = 9;
        [self.bgView addSubview:self.btn2];
        
        self.btn3 = [[UIButton alloc] initWithFrame:CGRectMake(self.btn2.nim_right + 4, 4, 52, 32)];
        [self.btn3 setTitle:@"驳回" forState:0];
        self.btn3.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn3 setTitleColor:HexColor(0x9C9DB3) forState:0];
        self.btn3.layer.masksToBounds = YES;
        self.btn3.layer.cornerRadius = 6;
        [self.btn3 setBackgroundColor:HexColor(0xF2F2F5)];
        [self.btn3 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        self.btn3.tag = 3;
        [self.bgView addSubview:self.btn3];
    }
    return self;
}

-(void)setTitleStr:(NSString *)titleStr {
    _titleStr = titleStr;
    self.titleLab.text = titleStr;
}

-(void)setS_type:(NSInteger)s_type {
    s_type = s_type;
    if (s_type == 1) {
        self.btn1.titleLabel.font = BoldFontOfSize(14);
        [self.btn1 setTitleColor:HexColor(0xffffff) forState:0];
        [self.btn1 setBackgroundColor:Color_ThemeColor];
        
        self.btn4.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn4 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn4 setBackgroundColor:HexColor(0xF2F2F5)];
        
        self.btn2.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn2 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn2 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn3.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn3 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn3 setBackgroundColor:HexColor(0xF2F2F5)];
    }else if (s_type == 9) {
        self.btn2.titleLabel.font = BoldFontOfSize(14);
        [self.btn2 setTitleColor:HexColor(0xffffff) forState:0];
        [self.btn2 setBackgroundColor:Color_ThemeColor];
        
        self.btn1.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn1 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn1 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn4.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn4 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn4 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn3.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn3 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn3 setBackgroundColor:HexColor(0xF2F2F5)];
    }else if (s_type == 3) {
        self.btn3.titleLabel.font = BoldFontOfSize(14);
        [self.btn3 setTitleColor:HexColor(0xffffff) forState:0];
        [self.btn3 setBackgroundColor:Color_ThemeColor];
        
        self.btn2.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn2 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn2 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn1.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn1 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn1 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn4.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn4 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn4 setBackgroundColor:HexColor(0xF2F2F5)];
    }else if (s_type == 11) {
        self.btn4.titleLabel.font = BoldFontOfSize(14);
        [self.btn4 setTitleColor:HexColor(0xffffff) forState:0];
        [self.btn4 setBackgroundColor:Color_ThemeColor];
        
        self.btn1.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn1 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn1 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn2.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn2 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn2 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn3.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn3 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn3 setBackgroundColor:HexColor(0xF2F2F5)];
    }
}

- (void)btnClick:(UIButton *)sender {
    if (sender.tag == 1) {
        self.btn1.titleLabel.font = BoldFontOfSize(14);
        [self.btn1 setTitleColor:HexColor(0xffffff) forState:0];
        [self.btn1 setBackgroundColor:Color_ThemeColor];
        
        self.btn2.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn2 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn2 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn3.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn3 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn3 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn4.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn4 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn4 setBackgroundColor:HexColor(0xF2F2F5)];
    }else if (sender.tag == 9) {
        self.btn2.titleLabel.font = BoldFontOfSize(14);
        [self.btn2 setTitleColor:HexColor(0xffffff) forState:0];
        [self.btn2 setBackgroundColor:Color_ThemeColor];
        
        self.btn1.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn1 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn1 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn3.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn3 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn3 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn4.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn4 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn4 setBackgroundColor:HexColor(0xF2F2F5)];
    }else if (sender.tag == 3) {
        self.btn3.titleLabel.font = BoldFontOfSize(14);
        [self.btn3 setTitleColor:HexColor(0xffffff) forState:0];
        [self.btn3 setBackgroundColor:Color_ThemeColor];
        
        self.btn2.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn2 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn2 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn1.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn1 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn1 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn4.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn4 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn4 setBackgroundColor:HexColor(0xF2F2F5)];
    }else if (sender.tag == 11) {
        self.btn4.titleLabel.font = BoldFontOfSize(14);
        [self.btn4 setTitleColor:HexColor(0xffffff) forState:0];
        [self.btn4 setBackgroundColor:Color_ThemeColor];
        
        self.btn1.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn1 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn1 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn2.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn2 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn2 setBackgroundColor:HexColor(0xF2F2F5)];
        self.btn3.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn3 setTitleColor:HexColor(0x9C9DB3) forState:0];
        [self.btn3 setBackgroundColor:HexColor(0xF2F2F5)];
    }
    if (self.changeBlock) {
        self.changeBlock(sender.tag);
    }
}

- (void)backClick {
    if (self.backBlock) {
        self.backBlock();
    }
}

@end
